#include "Rect.h"

ConcreteElementLoader<Rect> *Rect::loader = new ConcreteElementLoader<Rect>();

Rect::Rect(TiXmlElement *elem) { // TODO IMPLEMENT EXCEPTIONS
	if( elem != NULL ) {
		if( elem->QueryFloatAttribute("x1", &(point1.x)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("y1", &(point1.y)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("x2", &(point2.x)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("y2", &(point2.y)) == TIXML_SUCCESS ) {
			#ifdef DEBUG
			printf("Rectangle read: x1 = %0.1f, y1 = %0.1f, x2 = %0.1f, y2 = %0.1f\n", point1.x, point1.y, point2.x, point2.y);
			#endif
		}
	}
}

void Rect::displayElement() {
	glBegin(GL_POLYGON);
		glNormal3i(0, 0, 1);
		glVertex3f(point1.x, point1.y, 0.0);
		glVertex3f(point2.x, point1.y, 0.0);
		glVertex3f(point2.x, point2.y, 0.0);
		glVertex3f(point1.x, point2.y, 0.0);
	glEnd();
}